#line 1 "C:/Users/Tadsandre/Documents/ING4 2009-2010/PT/Simu UART HT/ADC_on_LCD.c"
char recept;
int coverflowbutton = 0;
int pushed = 0;


int convert(int mes)
{
return ((6787 / (mes*5 - 3)) - 4);
}

int identify (int id, int mes)
{

 if (mes <= 9) mes = mes + 10*id;
 else if (mes <= 99) mes = mes + 100*id;
 else if (mes <= 999) mes = mes + 1000*id;
 else if (mes <= 9999) mes = mes + 10000*id;
 return mes;
}
#line 40 "C:/Users/Tadsandre/Documents/ING4 2009-2010/PT/Simu UART HT/ADC_on_LCD.c"
void main() {
unsigned int toto;
int mesure;
char *text = "";
INTCON = 0x00;
ADCON1 = 0x82;
TRISA = 0x1C;
TRISB = 0x01;
TRISC = 0x00;
Usart_Init(2400);

while (1) {
 if (Usart_Data_Ready())
 {
 recept = Usart_Read();

 IntToStr(0, text);
 switch (recept)
 {
 case '1':
 mesure = ADC_read(0);

 mesure = identify(1,mesure);
 IntToStr(mesure, text);
 toto = 0;
 text[6] = 0x0A;
 text[7] = 0x0D;
 while ( text[toto] != 0x0D)
 {
 toto =toto+1;
 Usart_Write(text [toto]);
 }
 break;

 case '2': mesure = ADC_read(1);

 mesure = identify(2,mesure);
 IntToStr(mesure, text);
 toto = 0;
 text[6] = 0x0A;
 text[7] = 0x0D;
 while ( text[toto] != 0x0D)
 {
 toto =toto+1;
 Usart_Write(text [toto]);
 }
 break;

 case '3':
 IntToStr(30+coverflowbutton, text);
 toto = 0;
 text[6] = 0x0A;
 text[7] = 0x0D;
 while ( text[toto] != 0x0D)
 {
 toto =toto+1;
 Usart_Write(text [toto]);
 }
 }

 }

 if (PORTA.F4 == 1)
 {
 pushed = 1;
 }
 else if ((pushed == 1) &&(PORTA.F4==0) )
 {
 if(PORTA.F5 == 0) PORTA.F5 = 1;
 else PORTA.F5 = 0;
 if(coverflowbutton == 0) coverflowbutton = 1;
 else coverflowbutton = 0;

 pushed = 0;
 }

 }
}
